<script type="text/html" template lay-done="layui.data.permanentUpdatedone(d);">
    <div class='permanent-updateHtml-content'>
        <div class="layui-card">
            <div class="layui-card-body main-box">
                <div class="layui-innerbox" style="background-color: #fff;">
                    <div class="layui-row">
                        <div class="layui-col-md6">
                            <form class="layui-form permanent-updateHtml-form" action="" lay-filter="permanent-updateHtml-form-group">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">任务名称：</label>
                                    <div class="layui-input-inline" style="margin-left:23px;">
                                        <input type="text" disabled value='{{d.params.taskname ? d.params.taskname : ""}}' name="taskname" lay-verify="taskname" autocomplete="off" placeholder="请输入标题" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item" style="margin-top: 10px;">
                                    <div class="layui-form-item layui-form-text">
                                        <label class="layui-form-label">备注信息：</label>
                                        <div class="layui-input-block">
                                            <textarea disabled name="memo" placeholder="请输入内容" class="layui-textarea" style="min-height: 112px;">
                                                    {{d.params.memo ? d.params.memo : ""}}
                                            </textarea>
                                        </div>
                                    </div>
                                    <div class="special-content">
                                        <div class="special-key">
                                            <div id="permanent-upload-filie"><i class="layui-icon"></i>附件：</div>
                                        </div>
                                        <div class="special-value">
                                            <div class="check-value-box permanent-update-files"></div>
                                        </div>
                                    </div>
                                    <div class="special-content">
                                        <div class="special-key">
                                            <div ><i class="layui-icon">&#xe608;</i>下发单位</div>
                                        </div>
                                        <div class="special-value">
                                            <div class="check-value-box permanent-update-department">
                                                    {{#
                                                        if(d.params.deptMsg || d.params.groupMsg) {
                                                            var exitDep = d.params.deptMsg.length ? d.params.deptMsg : [],
                                                                exGgrp = d.params.groupMsg.length ? d.params.groupMsg : [],
                                                                allEx = exitDep.concat(exGgrp);
                                                            layui.each(allEx, function(index,item) {
                                                    }}
                                                        <div class="unit-content">
                                                            {{item.writeusername}}
                                                            <i class="layui-icon layui-icon-close T-event unit" data-target="delUnit" data-deptid="{{item.dataid}}"></i>
                                                        </div>
                                                    {{#
                                                            })
                                                        }
                                                    }}
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                       
                        <div class="layui-col-md6">
                            <form class="layui-form permanent-frequency-form" action="" lay-filter="permanent-frequency-form">
                                <!-- <div class="layui-inline" style="margin-bottom: 10px; display:inline-block;">
                                    <div class="layui-input-switch">
                                        <label class="layui-form-label"  style="text-align:left;">是否复核：</label>
                                        <div class="layui-input-inline"  style="width: 80px;">
                                            <div style="line-height: 35px;">{{ d.params.review && d.params.review === '1' ? "是" : "否"}}</div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-inline" style="margin-bottom: 10px;display:inline-block;">
                                    <div class="layui-review-box">
                                        <div class="review-content">
                                            <label class="layui-form-label" style="width: 84px;text-align:left;">附加复核人：</label>
                                            {{# if(d.params.review && d.params.review === '1'){ }}
                                                <div class="review-value-box T-event" data-target="to-review">
                                                    {{# layui.each(d.params.wadduserMsg, function(index, item){ }}
                                                        <span usercode="{{item.adduserdataid}}" certcode="{{item.adduserid}}">{{item.addusername}}</span>
                                                    {{# }) }}
                                                </div>
                                            {{# }else{ }}
                                                <div class="review-value-box layui-bg-gray T-event" data-target="to-review">
                                                    {{# layui.each(d.params.wadduserMsg, function(index, item){ }}
                                                        <span usercode="{{item.adduserdataid}}" certcode="{{item.adduserid}}">{{item.addusername}}</span>
                                                    {{# }) }}
                                                </div>
                                            {{# } }}
                                        </div>
                                    </div>
                                </div> -->
                                <div class="layui-form-item">
                                    <div class="layui-input-block fill-time-block" style="margin-top: 5px;">
                                        <div class="layui-form-item" style="padding: 10px 10px 0px 10px;">
                                            <div class="dateType" lay-filter="frequencyDateType"></div>
                                        </div>
                                    </div>
                                    <!-- <div style="display:none;">
                                        <label class="layui-form-label" style="text-align:left;">时间设置：</label>
                                        <div class="layui-input-block">
                                            <div class="leftType">
                                                <div class="topLeftType">
                                                    <input disabled type="radio" name="timeType" value="frequency" title="固定频率" lay-filter="timeType" {{ d.params.settype && d.params.settype === '0' ? "checked" : null}}>
                                                </div>
                                                <div class="bottomLeftType">
                                                    <input disabled type="radio" name="timeType" value="time" title="固定时间" lay-filter="timeType" {{ d.params.settype && d.params.settype === '1' ? "checked" : null}}>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="frequencyType">
                                        <div class="frequencyTypeDiv">
                                            <input disabled type="radio" name="frequencyType" lay-filter="frequencyTimeType" value="year" title="每年" {{ d.params.settype && d.params.settype === '1' ? "disabled" : null}} {{ d.params.hz && d.params.hz === 'year' ? "checked" : null}}>
                                        </div>
                                        <div class="frequencyTypeDiv">
                                            <input disabled type="radio" name="frequencyType" lay-filter="frequencyTimeType" value="quarter" title="每季度" {{ d.params.settype && d.params.settype === '1' ? "disabled" : null}} {{ d.params.hz && d.params.hz === 'quarter' ? "checked" : null}}>
                                        </div>
                                        <div class="frequencyTypeDiv">
                                            <input disabled type="radio" name="frequencyType" lay-filter="frequencyTimeType" value="month" title="每月" {{ d.params.settype && d.params.settype === '1' ? "disabled" : null}} {{ d.params.hz && d.params.hz === 'month' ? "checked" : null}}>
                                        </div>
                                        <div class="frequencyTypeDiv">
                                            <input disabled type="radio" name="frequencyType" lay-filter="frequencyTimeType" value="week" title="每周" {{ d.params.settype && d.params.settype === '1' ? "disabled" : null}} {{ d.params.hz && d.params.hz === 'week' ? "checked" : null}}>
                                        </div>
                                        <div class="frequencyTypeDiv">
                                            <input disabled type="radio" name="frequencyType" lay-filter="frequencyTimeType" value="day" title="每日" {{ d.params.settype && d.params.settype === '1' ? "disabled" : null}} {{ d.params.hz && d.params.hz === 'day' ? "checked" : null}}>
                                        </div>
                                    </div>
                                    <div class="layui-input-block fill-time-block" style="margin-top: 5px;">
                                        <div class="layui-form-item" style="padding: 10px 10px 0px 10px;">
                                            <div class="dateType" lay-filter="frequencyDateType"></div>
                                            <div class="listType">
                                                <div class="header">
                                                    最近5次填报时间
                                                    <button type="button" style="float: right;" class="layui-btn layui-btn-sm T-event" data-target="viewlast">查看</button>
                                                </div>
                                                <div class="body"></div>
                                            </div>
                                        </div>
                                    </div> -->
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</script>
<style>
.permanent-updateHtml-content * {
    box-sizing: content-box;
}
.layui-input-inline input, .layui-input-block textarea {
    box-sizing: border-box;
}
.permanent-updateHtml-content .layui-form-item{
    margin: 0;
}
.layui-innerbox{
    border: 1px solid #D2D2D2;
    border-radius: 4px;
    padding-top: 17px;
}
.permanent-updateHtml-content .layui-form-item .layui-inline {
    margin-right: 0px;
    width: 49%;
}
/* .permanent-updateHtml-content .layui-form-label:nth-child(4){
    padding:0px;
} */
.permanent-updateHtml-content .mustred{
    display: block;
    color: red;
    line-height: 45px;
    height: 0px;
}
.permanent-updateHtml-content .layui-form-item .layui-input-inline {
    width: 67%;
}
.permanent-updateHtml-content .layui-input-block{
    width: 67%;
}
.permanent-updateHtml-content .fill-time-block {
    /* border: 1px solid rgb(167,198,238); */
    border-radius: 6px;
    width: 100% !important;
    height: auto;
    margin: 0;
   /*  -ms-behavior: url(../../dist/style/res/PIE.htc);
    behavior: url(../../dist/style/res/PIE.htc); */
}
.permanent-updateHtml-content .layui-form-switch {
    background: #D2D2D2;
    width: 60%;
}
.permanent-updateHtml-content .layui-form-switch em {
    margin-left: 28px;
    color: #fff!important;
}
.permanent-updateHtml-content .layui-form-onswitch em {
    margin-left: 9px !important;
}
.permanent-updateHtml-content .layui-form-switch i {
    background-color: #fff;
}
.permanent-updateHtml-content .layui-form-onswitch i {
    margin-left: -22px;
}
.permanent-updateHtml-content .layui-btn-xs {
    height: 38px;
    background: #2669B1;
    margin-top: -8px;
    border-radius: 5px;
    width: 90px;
    margin-left: 5px;
   /*  -ms-behavior: url(../../dist/style/res/PIE.htc);
    behavior: url(../../dist/style/res/PIE.htc); */
}
.permanent-updateHtml-content .special-value {
    overflow: hidden;
    border: 1px solid #ccc;
    height: 38px;
    width: 67%;
    border-radius: 6px;
    border: 1px solid rgb(197,197,197);
    /* -ms-behavior: url(../../dist/style/res/PIE.htc);
    behavior: url(../../dist/style/res/PIE.htc); */
}
.permanent-updateHtml-content .layui-input, .layui-textarea{
    border-radius: 6px;
    border: 1px solid rgb(197,197,197);
    /* -ms-behavior: url(../../dist/style/res/PIE.htc);
    behavior: url(../../dist/style/res/PIE.htc); */
}
.permanent-updateHtml-content .layui-form-onswitch{
    border-color: #2669B1;
    background-color: #2669B1;
}
.permanent-updateHtml-content .special-content {
    width: 100%;
    margin-top: 26px;
}
.permanent-updateHtml-content .special-key {
    overflow: hidden;
    width: 96px;
    float: left;
    padding: 9px 3px;
    padding-right: 10px;
    text-align: left;
}
.permanent-updateHtml-content .iframeContent {
    width: 100%;
    /* height: 532px; */
    height: 475px;
    overflow: hidden;
}

.permanent-updateHtml-content .iframeContent .permanent-updateHtml-form {
    width: 99%;
    height: 100%;
    overflow: auto;
}
.permanent-updateHtml-form{
    background-color: #FFFFFF;
    padding: 11px;
}
.permanent-updateHtml-content .buttons-area {
    height: 40px;
    text-align: center;
    background-color: #FFFFFF;
    padding-top: 10px;
}
.buttons-area button{
    background-color: #2669B1;
}
.permanent-updateHtml-content .check-value-box {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    padding: 2px 2px;
}
.permanent-updateHtml-content .unit-content {
    display: inline-block;
    padding: 2px 5px;
    padding-right: 15px;
    background-color: #ccc;
    position: relative;
    height: 20px;
    line-height: 20px;
}

/* .permanent-updateHtml-content .unit-content:hover i{
    visibility: visible;
    color: red;
    font-weight: 600;
} */

.permanent-updateHtml-content .unit-content i {
    position: absolute;
    right: 0px;
    top: -2px;
    font-size: 14px;
    cursor: pointer;
    visibility: hidden;
}
.permanent-updateHtml-content .layui-form-radio {
    margin: 6px 0px 0 0px;
}
.permanent-updateHtml-content .layui-form-radio>i:hover, .layui-form-radioed>i {
    color: #276AB1;
}
.permanent-updateHtml-content .layui-input-block .leftType {
    width: 100%;
    height: 40px;
    display: flex;
}
.permanent-updateHtml-content .frequencyType {
    width: 100%;
    margin: 0 auto;
    height: 40px;
    border-bottom: 1px rgb(210,210,210) solid;
}
.permanent-updateHtml-content .frequencyTypeDiv{
    float: left;
    width: 20%;
    height: 40px;
}
.permanent-frequency-form{
    width: 90%;
    margin: 6px auto;
    margin-top: 0px;
}
.permanent-frequency-form .dateType {
    width: 90%;
    height: 100%;
    min-height: 187px;
    float: left;
    /* border-right: 1px solid #ccc; */
}
.permanent-frequency-form .date-item {
    width: 100%;
    height: 32px;
    clear: both;
}
.permanent-frequency-form .dateType .layui-btn-sm{
    height: 30px;
    line-height: 23px;
    padding: 0px 6px 0px 8px;
    font-size: 12px;
    border: 1px #009688 solid;
    background-color: transparent;
    border-radius: 6px;
    color: #009688;
    margin-right: 5px;
    /* -ms-behavior: url(../../dist/style/res/PIE.htc);
    behavior: url(../../dist/style/res/PIE.htc); */
}
.permanent-frequency-form .listType .layui-btn-sm{
    height: 30px;
    line-height: 23px;
    padding: 0px 6px 0px 8px;
    font-size: 12px;
    border: 1px #009688 solid;
    background-color: transparent;
    border-radius: 6px;
    color: #009688;
    /* -ms-behavior: url(../../dist/style/res/PIE.htc);
    behavior: url(../../dist/style/res/PIE.htc); */
}
.permanent-frequency-form .date-item input {
    line-height: 32px;
    box-sizing: border-box;
}
.permanent-frequency-form .dateType .layui-form-mid {
    padding: 7px 0px !important;
}
.permanent-frequency-form .date-item .layui-input {
    height: 30px;
}
.permanent-frequency-form .listType {
    width: 34%;
    float: left;
    height: 100%;
}
.permanent-frequency-form .listType .header {
    height: 30px;
    text-align: center;
    line-height: 30px;
    font-size: 14px;
}
.permanent-frequency-form .listType .body {
    width: 100%;
    height: 157px;
    overflow-y: auto;
    text-align: center;
}
/* 滚动条样式 */
::-webkit-scrollbar{
	width: 4px;
	height: 4px;
}
::-webkit-scrollbar-thumb{
	border-radius: 5px;
    -webkit-box-shaow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    background: rgba(0,0,0,0.2);
}
::-webkit-scrollbar-track{
	border-radius: 0;
    background: rgba(0,0,0,0.1);
}

.layui-layer{
	border-radius: 8px;
}
.layui-form-label{
	padding: 8px 3px;
}
.layui-layer-setwin{
    top: 10px;
    right: 11px;
}
.layui-layer-setwin .layui-layer-close1{
    background-position: 0 0;
}
.layui-layer-setwin a{
    width: 18px;
    height: 18px;
    margin: 0;
    background: url('/src/style/res/formFill/layer-close.png') no-repeat center center;
    background-position: 0px 0px;
}
.main-box{
    padding: 0 10px;
}
/* .permanent-updateHtml-content .layui-card{
    background: linear-gradient(137deg, #1D5BAE, #51AFBC);
} */
.permanent-updateHtml-content .layui-form-item .layui-inline .layui-review-box span{
    display: inline-block;
    height: 40px;
    line-height: 40px;
    color: #666;
    cursor: pointer;
    vertical-align: top;
}
.to-verify{
    margin-left: 78px;
}
.review-value-box, .audit-value-box{
    width: 220px;
    height: 35px;
	line-height: 20px;
	border-radius: 6px;
	margin-left: 10px;
	overflow-y: scroll;
	border: 1px solid #cccccc;
}
</style>
<script type="text/html" id="permanentTimeItemTpl">
    {{# 
        var isFirst=d.isFirst;
    }}
    <div class="date-item">
        <div class="layui-input-inline" style="width: 190px;">
            开始时间：
            <input disabled type="text" style="width: 110px;display:inline-block;" name="starttime" value="{{d.data.starttime || ''}}" class="layui-input item-time item-time-start" data-timetype="start" placeholder="选择时间">
        </div>
        <div class="layui-input-inline" style="width: 10px;">&nbsp;&nbsp;&nbsp;&nbsp;</div>
        <div class="layui-input-inline" style="width: 190px;">
            结束时间：
            <input disabled type="text" style="width: 110px;display:inline-block;" name="endtime" value="{{d.data.endtime || ''}}" class="layui-input item-time item-time-end" data-timetype="end" placeholder="选择时间">
        </div>
    </div>
</script>
<script type="text/html" id="permanentselectunitTpl">
    {{#
        layui.each(d, function(index,item) {
    }}
        <div class="unit-content">
            {{item.writeusername}}
            <i class="layui-icon layui-icon-close T-event unit" data-target="delUnit" data-deptid="{{item.dataid}}"></i>
        </div>
    {{#
        })
    }}
</script>
<script type="text/html" id="permanentselectgroupTpl">
    {{#
        layui.each(d, function(index,item) {
    }}
        <div class="unit-content">
            {{item.writeusername}}
            <i class="layui-icon layui-icon-close T-event group" data-target="delUnit" data-deptid="{{item.dept_id}}"></i>
        </div>
    {{#
        })
    }}
</script>
<script type="text/html" id="permanentShowLastTpl">
    {{#
        layui.each(d, function(index,item) {
    }}
        <div style="background-color:#ccc;border-radius: 6px;margin-top: 5px;">
            <p>开始：{{item.starttime}}</p>
            <p>结束：{{item.endtime}}</p>
        </div>
    {{#
        })
    }}
</script>
<script type="text/html" id="permanentuploadFilesTpl">
    {{#
        layui.each(d, function(index,item) {
    }}
        <div class="unit-content">
            <a class="T-event" data-target="download" href="javascript: void(0);" data-url="{{item.url}}">{{item.filename}}</a>
            <i class="layui-icon layui-icon-close T-event" data-target="delFile" data-deptid="{{item.servername}}"></i>
        </div>
    {{#
        })
    }}
</script>
<script>
layui.data.permanentUpdatedone = function (d) { 
    layui.use(['admin', 'form', 'laydate', 'upload', 'tools'], function(){
        var $ = layui.$,
        admin = layui.admin,
        view = layui.view,
        element = layui.element,
        layer = layui.layer,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        upload = layui.upload,
        setter = layui.setter,
        tools = layui.tools,
        form = layui.form,
        filenames = [],
        timeInputType = 'year', // year, quarter, month, week ,day
        switchKey = parseInt(d.params.review) || 0;
        
        form.render(null, 'permanent-updateHtml-form-group');
        form.render(null, 'permanent-frequency-form');

        if(d.params.id) { //修改
            var timeDate = d.params.timeDate && d.params.timeDate.length && d.params.timeDate.length > 0 ? d.params.timeDate : [];
            /* if(timeDate.length > 0) {
                $.each(timeDate, function(index, item) {
                    item.starttime = moment(item.starttime).format('YYYY-MM-DD');
                    item.endtime = moment(item.endtime).format('YYYY-MM-DD');
                    insertDateTplByType(index === 0, item);
                })
            }else {
                insertDateTplByType(true);
            } */
            insertDateTplByType(true, {starttime: d.params.starttime, endtime: d.params.endtime});
            var exitFileNames = d.params.fileNames;
            if(exitFileNames.length > 0) {
                filenames = exitFileNames;
                var Tplhtml = permanentuploadFilesTpl.innerHTML;
                var $tplF =$('.permanent-update-files');
                laytpl(Tplhtml).render(exitFileNames, function(html){
                    $tplF.html(html);
                });
            }
        }else { //新增
            insertDateTplByType(true);
        }

        //频率类型为频率时，根据时间来插入不同的时间选择组件
        function insertDateTplByType(isFirst,values) {
            var getTpl = permanentTimeItemTpl.innerHTML;
            var $tplC =$('.permanent-frequency-form .dateType');
            laytpl(getTpl).render({isFirst: isFirst, data: !!values ? values : {} }, function(html){
                var $ItemHtml = $(html);
                //给第一个时间行绑定时间组件
                bindTypeForItem($ItemHtml);
                !!isFirst ? $tplC.html($ItemHtml) : $tplC.append($ItemHtml);
                form.render(null, 'permanent-frequency-form');
            });
        }


        //给时间行绑定相应的时间操作
        function bindTypeForItem($ItemContariner, times) {
            $ItemContariner.each(function(index, el) {
                var commonMin = { year: 1900, month: 0, date: 1},
                    commonMax = { year: 2099, month: 11, date: 31};
                switch(timeInputType) {
                    case 'year':
                    var startDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-start').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                endDate.config.min = {
                                    year:date.year,
                                    month:date.month-1, 
                                    date: date.date,
                                };
                                endDate.config.max ={
                                    year: date.year+1,
                                    month:date.month-1, 
                                    date: date.date,
                                };
                            }else {
                                endDate.config.min = commonMin;
                                endDate.config.max = commonMax;
                            }
                        }
                    })
                    var endDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-end').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                startDate.config.min = {
                                    year: date.year-1,
                                    month: date.month - 1,
                                    date: date.date,
                                } 
                                startDate.config.max = {
                                    year: date.year,
                                    month: date.month - 1,
                                    date: date.date,
                                } 
                            }else {
                                startDate.config.min = commonMin;
                                startDate.config.max = commonMax; 
                            }
                        }
                    });
                    break;
                    case 'quarter':
                    var startDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-start').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                endDate.config.min = {
                                    year:date.year,
                                    month:date.month-1, 
                                    date: date.date,
                                };
                                var newDate = moment(value).add(3, 'M');
                                endDate.config.max ={
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                };
                            }else {
                                endDate.config.min = commonMin;
                                endDate.config.max = commonMax;
                            }
                        }
                    })
                    var endDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-end').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                var newDate = moment(value).subtract(3, 'M');
                                startDate.config.min = {
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                } 
                                startDate.config.max = {
                                    year: date.year,
                                    month: date.month - 1,
                                    date: date.date,
                                } 
                            }else {
                                startDate.config.min = commonMin;
                                startDate.config.max = commonMax; 
                            }
                        }
                    });
                    break;
                    case 'month':
                    var startDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-start').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                endDate.config.min = {
                                    year:date.year,
                                    month:date.month-1, 
                                    date: date.date,
                                };
                                var newDate = moment(value).add(1, 'M');
                                endDate.config.max ={
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                };
                            }else {
                                endDate.config.min = commonMin;
                                endDate.config.max = commonMax;
                            }
                        }
                    })
                    var endDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-end').get(0),
                        done: function (value, date) {
                            if(!!value) {
                                var newDate = moment(value).subtract(1, 'M');
                                startDate.config.min = {
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                } 
                                startDate.config.max = {
                                    year: date.year,
                                    month: date.month - 1,
                                    date: date.date,
                                } 
                            }else {
                                startDate.config.min = commonMin;
                                startDate.config.max = commonMax; 
                            }
                        }
                    });
                    break;
                    case 'week':
                        var startDate = laydate.render({
                            elem: $ItemContariner.find('.item-time-start').get(0),
                            done: function (value, date) {
                                if(!!value) {
                                    endDate.config.min = {
                                        year:date.year,
                                        month:date.month-1, 
                                        date: date.date,
                                    };
                                    var newDate = moment(value).add(1, 'w');
                                    endDate.config.max ={
                                        year: newDate.year(),
                                        month: newDate.month(),
                                        date: newDate.date(),
                                    };
                                }else {
                                    endDate.config.min = commonMin;
                                    endDate.config.max = commonMax;
                                }
                            }
                        })
                        var endDate = laydate.render({
                            elem: $ItemContariner.find('.item-time-end').get(0),
                            done: function (value, date) {
                                if(!!value) {
                                    var newDate = moment(value).subtract(1, 'w');
                                    startDate.config.min = {
                                        year: newDate.year(),
                                        month: newDate.month(),
                                        date: newDate.date(),
                                    } 
                                    startDate.config.max = {
                                        year: date.year,
                                        month: date.month - 1,
                                        date: date.date,
                                    } 
                                }else {
                                    startDate.config.min = commonMin;
                                    startDate.config.max = commonMax; 
                                }
                            }
                        });
                    break;
                    case 'day':
                    var startDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-start').get(0),
                        type: 'datetime',
                        format: 'yyyy-MM-dd HH',
                        done: function (value, date) {
                            if(!!value) {
                                endDate.config.min = {
                                    year:date.year,
                                    month:date.month-1, 
                                    date: date.date,
                                    hours: date.hours,
                                    minutes: 0,
                                    seconds: 0
                                };
                                var newDate = moment(value).add(1, 'd');
                                endDate.config.max ={
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                    hours: newDate.hours(),
                                    minutes: 0,
                                    seconds: 0
                                };
                            }else {
                                endDate.config.min = commonMin;
                                endDate.config.max = commonMax;
                            }
                        }
                    })
                    var endDate = laydate.render({
                        elem: $ItemContariner.find('.item-time-end').get(0),
                        type: 'datetime',
                        format: 'yyyy-MM-dd HH',
                        done: function (value, date) {
                            if(!!value) {
                                var newDate = moment(value).subtract(1, 'd');
                                startDate.config.min = {
                                    year: newDate.year(),
                                    month: newDate.month(),
                                    date: newDate.date(),
                                    hours: newDate.hours(),
                                    minutes: 0,
                                    seconds: 0
                                } 
                                startDate.config.max = {
                                    year: date.year,
                                    month: date.month - 1,
                                    date: date.date,
                                    hours: date.hours,
                                    minutes: 0,
                                    seconds: 0
                                } 
                            }else {
                                startDate.config.min = commonMin;
                                startDate.config.max = commonMax; 
                            }
                        }
                    });
                    break;
                    default:
                    break;
                }
                
            })
        }

        var selectDep = d.params.deptMsg || [],
            selectGrp = d.params.groupMsg || [],
            originDep = [],
            originGrp = [];
            $.each(selectDep, function(i,e) {
                e.dept_id = e.dataid;
                originDep.push(e);
            });
            $.each(selectGrp, function(i,e) {
                e.dept_id = e.dataid;
                originGrp.push(e);
            });
        window.selectTable = d.params.formMsg || [];

        //加载编辑时已选择的表单
        var mainIframe = document.getElementById('mainFormIframeInPermanent');
        $(mainIframe).load(function(){
            if(d.params.formMsg && d.params.formMsg.length > 0){
                var formContanier = mainIframe.contentWindow.document.querySelector('.select-nodes-list ul');
                var chooseNodes = d.params.formMsg;
                var lihtml = '';
                if(chooseNodes && chooseNodes.length > 0){
                    for(var i = 0; i < chooseNodes.length; i++){
                        if(i == 0){
                            lihtml += "<li class='liactive' id='"+chooseNodes[i].id+"' data-model='normal' data-tablename='"+chooseNodes[i].tablename+"' data-formid='"+chooseNodes[i].form_id+"' data-id='"+chooseNodes[i].id+"' data-html='"+chooseNodes[i].html+"'>"+chooseNodes[i].formname+"</li>"
                        }else{
                            lihtml += "<li data-model='normal' id='"+chooseNodes[i].id+"' data-tablename='"+chooseNodes[i].tablename+"' data-formid='"+chooseNodes[i].form_id+"' data-id='"+chooseNodes[i].id+"' data-html='"+chooseNodes[i].html+"'>"+chooseNodes[i].formname+"</li>"
                        }
                    }
                    formContanier.innerHTML = lihtml;
                    var firstLi = formContanier.querySelector('li');
                    firstLi.click();
                }
            }
            var buttons = $(mainIframe.contentWindow.document).find('button');
            $.each(buttons, function(index, el) {
                $(el).attr('disabled', 'true');
            })
        })

        //页面按钮点击事件
        $('.permanent-updateHtml-content').on('click', '.T-event', function() {
            var $container = $('.permanent-updateHtml-content');
            var target = $(this).data('target');
              if (target === 'viewlast') {
                var $form = $('.permanent-updateHtml-content .permanent-frequency-form');
                var arr = tools.getAreaArgs($form.find('.dateType .date-item'), {type: 'array'}, function($obj) {
                    var starttime = $obj.find('.item-time-start').val(),
                        endtime = $obj.find('.item-time-end').val();
                    return !!starttime && !!endtime;
                });
                // var hz = $form.find('input[name="frequencyType"]').val();
                var hz = $('.frequencyType').find('input[name="frequencyType"]:checked').val();
                var timeDate = [];
                $.each(arr, function(index, item) {
                    item.starttime = moment(item.starttime).format('YYYY-MM-DD HH:mm:ss');
                    item.endtime = moment(item.endtime).format('YYYY-MM-DD HH:mm:ss');
                    timeDate.push(item);
                })
                var args = {
                    hz: hz,
                    timeDate: timeDate
                }
                if(timeDate.length === 0) {
                    layer.msg('请先选择至少一组开始结束时间');
                    return false;
                }
                admin.req({
                    url: 'myapi/DC/api/rest/web/custom/getthelatesttime',
                    type: 'post',
                    data: {time: JSON.stringify(args)},
                    success: function(res){
                        var getTpl = permanentShowLastTpl.innerHTML;
                        var $tplC =$('.permanent-frequency-form .listType .body');
                        laytpl(getTpl).render(res.data, function(html){
                            $tplC.html(html);
                        });
                    }
                });
            }
        })
    });
}

</script>